import json
json_file_path = '/mnt/d/WSL/consisi-demo/model.json'
json_file = open(json_file_path, mode='w')
 
# save_json_content = []
# data=["D_A","D_B"]
# server=["S_A","S_B","S_C","S_D","S_E"]
# F_dependence=["D_A<-->S_A","D_A<-->S_B","S_C-->S_A","S_B-->S_C","S_A-->S_D","S_A-->S_E","D_B-->S_E"]
# F_degrade=[["S_A","S_B"],["S_C","S_D"],["S_E"]]#重要->次要

data=[]
server=["NGX_MAIL_MODULE","ngx_mail_smtp_module","ngx_mail_auth_module","ngx_mail_imap_module","ngx_mail_proxy_module","ngx_mail_pop3_module","ngx_mail_core_module","ngx_mail_ssl_module",
"NGX_HTTP_MODULE","ngx_http_stub_status_module","ngx_http_upstream_module","ngx_http_fastcgi_module","ngx_http_limit_conn_module","ngx_http_log_module","ngx_http_access_module","ngx_http_proxy_module","ngx_http_auth_basic_module","ngx_http_core_module","ngx_http_gzip_module","ngx_http_ssl_module","ngx_http_limit_req_module","ngx_http_rewrite_module","ngx_http_request",
"NGX_EVENT_MODULE","ngx_epoll_module","ngx_event_accept","ngx_event_actions","ngx_event_core_module","ngx_event_openssl_module","ngx_process_cycle","ngx_worker_process_cycle","ngx_process_events_and_timers",
"NGX_CONF_MODULE",
"NGX_CORE_MODULE","ngx_regex_module","ngx_google_perftools_module","md5","sha",
"openssl_module"]
F_dependence=["ngx_mail_ssl_module-->ngx_mail_auth_module","ngx_mail_ssl_module-->ngx_mail_smtp_module","ngx_mail_ssl_module-->ngx_mail_core_module","ngx_mail_ssl_module-->ngx_mail_imap_module","ngx_mail_ssl_module-->ngx_mail_pop3_module",
"ngx_mail_core_module-->ngx_mail_auth_module","ngx_mail_core_module-->ngx_mail_smtp_module","ngx_mail_core_module-->ngx_mail_imap_module","ngx_mail_core_module-->ngx_mail_proxy_module","ngx_mail_core_module-->ngx_mail_pop3_module","ngx_mail_core_module-->NGX_MAIL_MODULE",
"ngx_http_core_module-->ngx_http_upstream_module","ngx_http_core_module-->ngx_http_fastcgi_module","ngx_http_core_module-->ngx_http_limit_conn_module","ngx_http_core_module-->ngx_http_access_module","ngx_http_core_module-->ngx_http_proxy_module","ngx_http_core_module-->ngx_http_auth_basic_module","ngx_http_core_module-->ngx_http_gzip_module","ngx_http_core_module-->ngx_http_ssl_module","ngx_http_core_module-->ngx_http_limit_req_module","ngx_http_core_module-->ngx_http_rewrite_module","ngx_http_core_module-->ngx_http_request",
"ngx_http_upstream_module-->ngx_http_fastcgi_module","ngx_http_upstream_module-->ngx_http_proxy_module","ngx_http_ssl_module-->NGX_HTTP_MODULE",
"ngx_http_request-->ngx_http_upstream_module","ngx_http_request-->ngx_http_fastcgi_module","ngx_http_request-->ngx_http_limit_conn_module","ngx_http_request-->ngx_http_proxy_module","ngx_http_request-->ngx_http_access_module","ngx_http_request-->ngx_http_gzip_module","ngx_http_request-->NGX_HTTP_MODULE","ngx_http_request-->ngx_http_limit_req_module","ngx_http_request-->ngx_http_ssl_module","ngx_http_request-->ngx_http_rewrite_module",
"ngx_worker_process_cycle-->ngx_process_cycle",
"ngx_process_events_and_timers-->ngx_process_cycle","ngx_process_events_and_timers-->NGX_EVENT_MODULE",
"ngx_event_actions-->ngx_epoll_module","ngx_event_actions-->NGX_EVENT_MODULE",
"ngx_event_core_module-->ngx_epoll_module","ngx_event_core_module-->NGX_EVENT_MODULE","ngx_event_core_module-->ngx_event_accept",
"ngx_event_accept-->NGX_EVENT_MODULE",
"ngx_epoll_module-->NGX_EVENT_MODULE",
"NGX_CORE_MODULE-->NGX_MAIL_MODULE","NGX_CORE_MODULE-->ngx_google_perftools_module","NGX_CORE_MODULE-->ngx_regex_module","NGX_CORE_MODULE-->NGX_EVENT_MODULE","NGX_CORE_MODULE-->NGX_HTTP_MODULE","NGX_CORE_MODULE-->md5","NGX_CORE_MODULE-->sha","NGX_CORE_MODULE<-->ngx_event_openssl_module",
"openssl_module-->md5","openssl_module-->sha","openssl_module-->ngx_event_openssl_module",
"NGX_CONF_MODULE-->ngx_mail_ssl_module","NGX_CONF_MODULE-->ngx_mail_core_module","NGX_CONF_MODULE-->ngx_mail_smtp_module","NGX_CONF_MODULE-->ngx_mail_imap_module","NGX_CONF_MODULE-->ngx_mail_proxy_module","NGX_CONF_MODULE-->ngx_mail_pop3_module","NGX_CONF_MODULE-->NGX_MAIL_MODULE","NGX_CONF_MODULE-->ngx_http_stub_status_module","NGX_CONF_MODULE-->ngx_http_upstream_module","NGX_CONF_MODULE-->ngx_http_fastcgi_module","NGX_CONF_MODULE-->ngx_http_log_module","NGX_CONF_MODULE-->ngx_http_access_module","NGX_CONF_MODULE-->ngx_http_proxy_module","NGX_CONF_MODULE-->NGX_HTTP_MODULE","NGX_CONF_MODULE-->ngx_http_auth_basic_module","NGX_CONF_MODULE-->ngx_http_core_module","NGX_CONF_MODULE-->ngx_http_gzip_module","NGX_CONF_MODULE-->ngx_http_ssl_module","NGX_CONF_MODULE-->ngx_http_limit_req_module","NGX_CONF_MODULE-->ngx_http_rewrite_module","NGX_CONF_MODULE-->ngx_http_request","NGX_CONF_MODULE-->ngx_event_accept","NGX_CONF_MODULE-->ngx_process_cycle","NGX_CONF_MODULE-->md5","NGX_CONF_MODULE-->sha","NGX_CONF_MODULE-->ngx_google_perftools_module",
]
F_degrade=[["NGX_CORE_MODULE","openssl_module","NGX_CONF_MODULE"],["ngx_regex_module","ngx_google_perftools_module","md5","sha"],["ngx_mail_core_module","ngx_http_core_module","ngx_event_core_module"],["NGX_HTTP_MODULE","ngx_http_stub_status_module","ngx_http_upstream_module","ngx_http_fastcgi_module","ngx_http_limit_conn_module","ngx_http_log_module","ngx_http_access_module","ngx_http_proxy_module","ngx_http_auth_basic_module","ngx_http_gzip_module","ngx_http_ssl_module","ngx_http_limit_req_module","ngx_http_rewrite_module","ngx_http_request"],["NGX_EVENT_MODULE","ngx_epoll_module","ngx_event_accept","ngx_event_actions","ngx_event_core_module","ngx_event_openssl_module","ngx_process_cycle","ngx_worker_process_cycle","ngx_process_events_and_timers"],["NGX_EVENT_MODULE","ngx_epoll_module","ngx_event_accept","ngx_event_actions","ngx_event_core_module","ngx_event_openssl_module","ngx_process_cycle","ngx_worker_process_cycle","ngx_process_events_and_timers"]]#重要->次要


F_degrade_dep=[]

for index in range(len(F_degrade)):
    if index+1<len(F_degrade):
        for i in range(len(F_degrade[index])):
            for j in range(len(F_degrade[index+1])):
                F_degrade_dep.append(F_degrade[index][i]+"-->"+F_degrade[index+1][j])



save_json_content={"Data":data,"Server":server,"Dep":F_dependence,"Degrade":F_degrade_dep}
# save_json_content.append({})
# save_json_content.append({"Server":server})
# save_json_content.append({"Dep":F_dependence})
# save_json_content.append({"Degrade":F_degrade}) 

json.dump(save_json_content, json_file, indent=4)  
# json.dump(save_json_content, json_file, ensure_ascii=False, indent=4) # 保存中文
